package model;

import java.util.ArrayList;

/** Class represents graph */
public class Graph {
	
	/** Vertex list */
	private ArrayList<Vertex> vertexList;
	
	/** Edge list */
	private ArrayList<Edge> edgeList;
	
	/** Constructor 
	 * 
	 */
	public Graph() {
		vertexList = new ArrayList<Vertex>();
		edgeList = new ArrayList<Edge>();
	}
	
	/** Method adds vertex
	 * 
	 * @param vertex Vertex
	 */
	public void addVertex (Vertex vertex) {
		vertexList.add (vertex);
	}
	
	/** Method adds edge
	 * 
	 * @param edge Edge
	 */
	public void addEdge (Edge edge) {
		edgeList.add (edge);
	}
	
	/** Method returns vertex list 
	 * 
	 * @return vertex list
	 */
	public ArrayList<Vertex> getVertexList() {
		return vertexList;
	}

	/** Method returns edge list */
	public ArrayList<Edge> getEdgeList() {
		return edgeList;
	}
	
	/** Method erases vertex and edge lists */
	public void erase() {
		vertexList.clear();
		edgeList.clear();
	}
	
	/** Method finds vertex by its unique id 
	 * 
	 * @param id Indicator
	 * @return
	 * @throws NoSuchVertexFoundException if not found
	 */
	public Vertex getVertexById (int id) throws NoSuchVertexFoundException {
		for (int i = 0; i < vertexList.size(); i++) {
			if (vertexList.get(i).getId() == id) {
				return vertexList.get(i);
			}
		}
		throw new NoSuchVertexFoundException();
	}
}